package org.wyn.mongodb.bean;

import java.util.ArrayList;
import java.util.List;

import org.apache.commons.lang.StringUtils;
import org.bson.types.ObjectId;
import org.wyn.common.Table;

import com.google.code.morphia.annotations.Entity;
import com.google.code.morphia.annotations.Id;
import com.google.code.morphia.annotations.Indexed;
/**
 * 新鲜事实体类
 * @author wyn
 *
 */
@Entity(value = Table.CollectionName.FRESHTHING, noClassnameStored = true)
public class FreshThing {
	public FreshThing(){
		
	}
	public FreshThing(String userName,String realName,FreshThingType type){
		this.userName = userName;
		this.realName = realName;
		this.type = type;
		this.createTime = System.currentTimeMillis();
	}
	@Id
	private ObjectId freshThingId;
	/**新鲜事拥有者(即这件事当事人)*/
	@Indexed
	private String userName;
	private String realName;
	/**当事人头像*/
	private ObjectId portraitId = new ObjectId();
	@Indexed
	private long createTime;
	/**新鲜事类型*/
	private FreshThingType type;
	/**
	 * 写日志
	 */
	private ObjectId blogId;
	private String title;//日志标题
	/**
	 * 成为好友
	 */
	private String friendUserName;//好友账号
	private String friendRealName;//好友姓名
	/**
	 * 上传照片
	 */
	private ObjectId albumId;
	private String albumName;
	private int uploadImageNum;//上传照片的张数
	private List<ObjectId> imageIds = new ArrayList<ObjectId>();//上传的照片id列表
	/**
	 * 发表状态
	 */
	private String statusContent;
	/**
	 * 构造写日志新鲜事
	 * @param blog
	 * @param userName
	 * @param realName
	 * @return 失败返回null(blog参数中数据异常就失败)
	 */
	public static FreshThing buildWriteBlog(Blog blog,String userName,String realName){
		//公共属性
		FreshThing ft = new FreshThing(userName,realName,FreshThingType.WRITEBLOG);
		//特有属性
		ft.blogId = blog.getBlogId();
		ft.title = blog.getTitle();
		if(null == ft.blogId || StringUtils.isEmpty(ft.title)){//检测数据有无异常
			return null;
		}
		return ft;
	}
	/**
	 * 构造成为好友新鲜事
	 * @param userName 当事人账号
	 * @param realName 当事人姓名
	 * @param friendUserName 好友账号
	 * @param friendRealName 好友姓名
	 * @return
	 */
	public static FreshThing buildBecomeFriend(String userName,String realName,String friendUserName,String friendRealName){
		FreshThing ft = new FreshThing(userName,realName,FreshThingType.BECOMEFRIEND);
		//特定属性
		ft.friendUserName = friendUserName;
		ft.friendRealName = friendRealName;
		return ft;
	}
	/**
	 * 构造上传图片新鲜事
	 * @param userName
	 * @param realName
	 * @param albumId
	 * @param albumName
	 * @param imageIds
	 * @return
	 */
	public static FreshThing buildUploadImage(String userName,String realName,ObjectId albumId,String albumName,List<ObjectId> imageIds){
		FreshThing ft = new FreshThing(userName,realName,FreshThingType.UPLOADIMAGE);
		ft.setAlbumId(albumId);
		ft.setAlbumName(albumName);
		ft.setUploadImageNum(imageIds.size());
		ft.setImageIds(imageIds);
		return ft;
	}
	/**
	 * 构造修改头像新鲜事
	 * @param userName
	 * @param realName
	 * @param portraitId 修改的头像图片Id
	 * @return
	 */
	public static FreshThing buildModifyPortrait(String userName,String realName,ObjectId portraitId){
		FreshThing ft = new FreshThing(userName,realName,FreshThingType.MODIFYPORTRAIT);
		ft.setPortraitId(portraitId);
		return ft;
	}
	public ObjectId getFreshThingId() {
		return freshThingId;
	}
	public void setFreshThingId(ObjectId freshThingId) {
		this.freshThingId = freshThingId;
	}
	public String getUserName() {
		return userName;
	}
	public void setUserName(String userName) {
		this.userName = userName;
	}
	public String getRealName() {
		return realName;
	}
	public void setRealName(String realName) {
		this.realName = realName;
	}
	public long getCreateTime() {
		return createTime;
	}
	public void setCreateTime(long createTime) {
		this.createTime = createTime;
	}
	public FreshThingType getType() {
		return type;
	}
	public void setType(FreshThingType type) {
		this.type = type;
	}
	public ObjectId getBlogId() {
		return blogId;
	}
	public void setBlogId(ObjectId blogId) {
		this.blogId = blogId;
	}
	public String getTitle() {
		return title;
	}
	public void setTitle(String title) {
		this.title = title;
	}
	public ObjectId getAlbumId() {
		return albumId;
	}
	public void setAlbumId(ObjectId albumId) {
		this.albumId = albumId;
	}
	public String getAlbumName() {
		return albumName;
	}
	public void setAlbumName(String albumName) {
		this.albumName = albumName;
	}
	public int getUploadImageNum() {
		return uploadImageNum;
	}
	public void setUploadImageNum(int uploadImageNum) {
		this.uploadImageNum = uploadImageNum;
	}
	public List<ObjectId> getImageIds() {
		return imageIds;
	}
	public void setImageIds(List<ObjectId> imageIds) {
		this.imageIds = imageIds;
	}
	public String getFriendUserName() {
		return friendUserName;
	}
	public void setFriendUserName(String friendUserName) {
		this.friendUserName = friendUserName;
	}
	public String getFriendRealName() {
		return friendRealName;
	}
	public ObjectId getPortraitId() {
		return portraitId;
	}
	public void setPortraitId(ObjectId portraitId) {
		this.portraitId = portraitId;
	}
	public void setFriendRealName(String friendRealName) {
		this.friendRealName = friendRealName;
	}
	public String getStatusContent() {
		return statusContent;
	}
	public void setStatusContent(String statusContent) {
		this.statusContent = statusContent;
	}
}
